package com.swt.dao.impl.W_impl;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class CourseDaoImpl{
    @Resource
    private HibernateTemplate hibernateTemplate;

    /**
     * 课程预约比例
     * */
    public List booking(int page) {
        String sql="SELECT\n" +
                "cl.club_name,\n" +
                "co.course_name,\n" +
                "ROUND((co.course_num-co.course_remainNum)/co.course_num*100,1) booking\n" +
                "FROM\n" +
                "club AS cl ,\n" +
                "course AS co\n" +
                "WHERE\n" +
                "cl.club_id = co.clubClubId ORDER BY booking DESC;\n";
        Session session=hibernateTemplate.getSessionFactory().getCurrentSession();
        Query query=session.createSQLQuery(sql);
        List list=query.list();
        return list;
    }
}
